home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Modules / Preferences / WindowDepth / Source / MyNXBrowserCell.m < prev    next >
Text File  |  1992-11-28  |  5KB  |  190 lines

  1.  
  2. #import "MyNXBrowserCell.h"
  3. #import "common.h"
  4.  
  5. #define FIRST_COLUMN_START 5.0
  6. #define SECOND_COLUMN_START 45.0
  7.  
  8. @implementation MyNXBrowserCell
  9.  
  10. static id     twoImage;
  11. static id    eightImage;
  12. static id     twelveImage;
  13. static id    twentyfourImage;
  14. static NXSize    imageSize;        // All assumed to be same size
  15.  
  16. /*=========================================================================
  17.  * NAME        : initTextCell:
  18.  * DESCRIPTION : Initialize a cell.
  19.  *=========================================================================*/
  20. - initTextCell:(const char *)aString
  21. {
  22.     id bundle = [NXBundle bundleForClass:[self class]];
  23.     char buf[MAXPATHLEN+1];
  24.     
  25.     [super initTextCell:aString];
  26.     
  27.     if (!twoImage) {
  28.         if ([bundle getPath:buf forResource:"2" ofType:"tiff"]) {
  29.             twoImage = [[NXImage alloc] initFromFile:buf];
  30.         }
  31.     [twoImage getSize:&imageSize];
  32.     }
  33.     if (!eightImage) {
  34.         if ([bundle getPath:buf forResource:"8" ofType:"tiff"]) {
  35.             eightImage = [[NXImage alloc] initFromFile:buf];
  36.         }
  37.     }
  38.     if (!twelveImage) {
  39.         if ([bundle getPath:buf forResource:"12" ofType:"tiff"]) {
  40.             twelveImage = [[NXImage alloc] initFromFile:buf];
  41.         }
  42.     }
  43.     if (!twentyfourImage) {
  44.         if ([bundle getPath:buf forResource:"24" ofType:"tiff"]) {
  45.             twentyfourImage = [[NXImage alloc] initFromFile:buf];
  46.         }
  47.     }
  48.     return self;
  49. }
  50.  
  51. /*=========================================================================
  52.  * NAME        : setTag:
  53.  * DESCRIPTION : Sets the cell's integer tag.
  54.  *=========================================================================*/
  55. - setTag:(int)aTag
  56. {
  57.     tag = aTag;
  58.     return self;
  59. }
  60.  
  61. /*=========================================================================
  62.  * NAME        : tag
  63.  * DESCRIPTION : Returns the cell's integer tag.
  64.  *=========================================================================*/
  65. - (int)tag
  66. {
  67.     return tag;
  68. }
  69.  
  70. /*=========================================================================
  71.  * NAME        : setOwner:
  72.  * DESCRIPTION : Set the owner attribute.
  73.  *=========================================================================*/
  74. - setOwner:(NXAtom)theOwner
  75. {
  76.     owner = theOwner;
  77.     return self;
  78. }
  79.  
  80. /*=========================================================================
  81.  * NAME        : owner
  82.  * DESCRIPTION : Return the owner attribute.
  83.  *=========================================================================*/
  84. - (NXAtom)owner
  85. {
  86.     return owner;
  87. }
  88.  
  89. /*=========================================================================
  90.  * NAME        : setDepth:
  91.  * DESCRIPTION : Set the WindowDepthLimit attribute.
  92.  *=========================================================================*/
  93. - setDepth:(int)theDepth;
  94. {
  95.     depth = theDepth;
  96.     switch (depth) {
  97.         case USE_2_BIT:
  98.         depthImage = twoImage;
  99.         break;
  100.     case USE_8_BIT:
  101.             depthImage = eightImage;
  102.         break;
  103.     case USE_12_BIT:
  104.             depthImage = twelveImage;
  105.         break;
  106.     case USE_24_BIT:
  107.         depthImage = twentyfourImage;
  108.         break;
  109.     default:
  110.         depthImage = nil;
  111.         break;
  112.     }
  113.     return self;
  114. }
  115.  
  116. /*=========================================================================
  117.  * NAME        : depth
  118.  * DESCRIPTION : Return the WindowDepthLimit.
  119.  *=========================================================================*/
  120. - (int)depth
  121. {
  122.     return depth;
  123. }
  124.  
  125. /*=========================================================================
  126.  * NAME        : setTestMode:
  127.  * DESCRIPTION : Sets the test flag.
  128.  *=========================================================================*/
  129. - setTestMode:(BOOL)flag
  130. {
  131.     test = flag;
  132.     return self;
  133. }
  134.  
  135. /*=========================================================================
  136.  * NAME        : testMode
  137.  * DESCRIPTION : Returns the state of the test mode flag.
  138.  *=========================================================================*/
  139. - (BOOL)testMode
  140. {
  141.     return test;
  142. }
  143.  
  144. /*===========================================================================
  145.  * NAME        : - setFont:
  146.  * DESCRIPTION : Set the cell font.
  147.  *===========================================================================*/
  148. - setFont:fontObj
  149. {
  150.     [super setFont:fontObj];
  151.     NXTextFontInfo(support, &ascender, &descender, &lineHeight);
  152.     return self;
  153. }    
  154.  
  155. /*===========================================================================
  156.  * NAME        : - drawInside:inView:
  157.  * DESCRIPTION : Draw the custom cell.
  158.  *===========================================================================*/
  159. - drawInside:(const NXRect *)cellFrame inView:controlView
  160. {
  161.     NXPoint    imageOrigin;
  162.     
  163.     [super drawInside:cellFrame inView:controlView];
  164.     
  165.     /* erase the cell */
  166.     PSsetgray((cFlags1.state || cFlags1.highlighted) ? NX_WHITE : NX_LTGRAY);
  167.     NXRectFill(cellFrame);
  168.     
  169.     /* draw the depth tiff */
  170.     if (depthImage) {
  171.         imageOrigin.x = FIRST_COLUMN_START;
  172.     imageOrigin.y = NX_Y(cellFrame) + NX_HEIGHT(cellFrame) -
  173.                     (NX_HEIGHT(cellFrame) - imageSize.height) / 2.0;
  174.     [depthImage composite:NX_SOVER toPoint:&imageOrigin];
  175.     }
  176.     
  177.     /* draw the text */
  178.     if (depth != USE_DEFAULT)
  179.         PSsetgray(NX_BLACK);
  180.     else
  181.         PSsetgray(NX_DKGRAY);
  182.     PSmoveto(NX_X(cellFrame) + SECOND_COLUMN_START,
  183.              NX_Y(cellFrame) + lineHeight - descender);
  184.     PSshow(contents);
  185.     
  186.     return self;
  187. }
  188.  
  189. @end
  190.